package com.ruoyi.merchant.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.merchant.domain.Combos;
import com.ruoyi.merchant.service.ICombosService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 套餐Controller
 * 
 * @author ruoyi
 * @date 2025-10-23
 */
@RestController
@RequestMapping("/merchant/combos")
public class CombosController extends BaseController
{
    @Autowired
    private ICombosService combosService;

    /**
     * 查询套餐列表
     */
    @PreAuthorize("@ss.hasPermi('merchant:combos:list')")
    @GetMapping("/list")
    public TableDataInfo list(Combos combos)
    {
        startPage();
        List<Combos> list = combosService.selectCombosList(combos);
        return getDataTable(list);
    }

    /**
     * 导出套餐列表
     */
    @PreAuthorize("@ss.hasPermi('merchant:combos:export')")
    @Log(title = "套餐", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Combos combos)
    {
        List<Combos> list = combosService.selectCombosList(combos);
        ExcelUtil<Combos> util = new ExcelUtil<Combos>(Combos.class);
        util.exportExcel(response, list, "套餐数据");
    }

    /**
     * 获取套餐详细信息
     */
    @PreAuthorize("@ss.hasPermi('merchant:combos:query')")
    @GetMapping(value = "/{comboId}")
    public AjaxResult getInfo(@PathVariable("comboId") String comboId)
    {
        return success(combosService.selectCombosByComboId(comboId));
    }

    /**
     * 新增套餐
     */
    @PreAuthorize("@ss.hasPermi('merchant:combos:add')")
    @Log(title = "套餐", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Combos combos)
    {
        return toAjax(combosService.insertCombos(combos));
    }

    /**
     * 修改套餐
     */
    @PreAuthorize("@ss.hasPermi('merchant:combos:edit')")
    @Log(title = "套餐", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Combos combos)
    {
        return toAjax(combosService.updateCombos(combos));
    }

    /**
     * 删除套餐
     */
    @PreAuthorize("@ss.hasPermi('merchant:combos:remove')")
    @Log(title = "套餐", businessType = BusinessType.DELETE)
	@DeleteMapping("/{comboIds}")
    public AjaxResult remove(@PathVariable String[] comboIds)
    {
        return toAjax(combosService.deleteCombosByComboIds(comboIds));
    }
}
